#ifndef _HIREDISUTILS_H_ 
#define _HIREDISUTILS_H_

#include "hiredis.h"

extern redisContext *globalRedisCtx;
/*
#define REDIS_REPLY_STRING 1
#define REDIS_REPLY_ARRAY 2
#define REDIS_REPLY_INTEGER 3
#define REDIS_REPLY_NIL 4
#define REDIS_REPLY_STATUS 5
#define REDIS_REPLY_ERROR 6
*/

#define REDIS_STRING 	REDIS_REPLY_STRING
#define REDIS_ARRAY	REDIS_REPLY_ARRAY
#define REDIS_INTEGER	REDIS_REPLY_INTEGER
#define REDIS_NULL	REDIS_REPLY_NIL
#define REDIS_STATUS	REDIS_REPLY_STATUS	/* return status information */
#define REDIS_ERROR	REDIS_REPLY_ERROR 

extern char redisError[201];

void redisShowReply(redisReply* reply, int deep);
redisContext* redis_connect(char *ip, int port);
redisReply* redis_command(char *commandBuf);
redisReply* redis_command_v(char *fmt, ...);

#define REDIS_EXE_ERROR			-1001

#define REDIS_CHECK_EXE_STATUS(reply, cmdBuf)					\
	do { 									\
		if (reply == NULL) {						\
			if (cmdBuf) {						\
				elog("CMD[%s] failed, error[%s]", cmdBuf, redisError);	\
			} else {						\
				elog("error[%s]", redisError);			\
			}							\
                        return REDIS_EXE_ERROR;					\
                } 								\
	} while(0)

#endif
